import unittest
import ddt
import pandas as pd, os

import sys
sys.path.append('/Users/user/Documents/Personnal/gra-books/clgllq/blackbox/zsh/CalTest/src')
from DateModel import myDate


def getData():
    res=[]
    for root, dirs, files in os.walk('../testcase/last'):
        for file in files:
            df = pd.read_excel(os.path.join(root, file))
            start = df['date'].values.tolist()
            delta = df['n'].values.tolist()
            output = df['output'].values.tolist()
            res.extend(list(zip(start, delta, output)))
    return res

@ddt.ddt
class TestNextNDate(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        print('start')

    @classmethod
    def tearDownClass(cls):
        print('stop')
    @ddt.data(*getData())
    @ddt.unpack
    def test_nextNDays(self,input,delta,output):
        print(input,delta,output)
        try:
            input = myDate(*[int(o) for o in input.split('/')])
            delta = delta
            output = myDate(*[int(o) for o in output.split('/')])
            result = input + delta if delta > 0 else input - abs(delta)
        except Exception as e:
            output = 'nan'
            result = 'nan'


        self.assertEqual(result.__str__(),output.__str__())



if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TestNextNDate)
    unittest.TextTestRunner(verbosity=2).run(suite)
    # print(getData())
    # unittest.main()
